package com.smh.a03DateDemo3;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class ZoneDateDemo1 {
    public static void main(String[] args) {
//带时区时间对象
        ZonedDateTime now =ZonedDateTime.now();
        System.out.println(now);

        //指定时间对象
        ZonedDateTime zonedDateTime = ZonedDateTime.of(2013,10,11,11,12,12,0, ZoneId.of("Asia/Shanghai"));
        System.out.println(zonedDateTime);

        //Instant+ZoneId 获取ZonedDateTime对象
        Instant i  = Instant.now();
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        ZonedDateTime zonedDateTime1 = ZonedDateTime.ofInstant(i,zoneId);
        System.out.println(zonedDateTime1);

        //修改
        ZonedDateTime zonedDateTime2 = zonedDateTime1.withYear(2000);
        ZonedDateTime zonedDateTime3 = zonedDateTime1.withHour(20);

        System.out.println(zonedDateTime2);
        System.out.println(zonedDateTime3);

        //减少时间
        ZonedDateTime zonedDateTime4 = zonedDateTime1.minusDays(2);
        System.out.println(zonedDateTime4);

        //添加
        ZonedDateTime zonedDateTime5 = zonedDateTime1.plusDays(4);
        System.out.println(zonedDateTime5);


    }
}
